package com.dabaozhan.modules.wx_app.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.dabaozhan.common.exception.RRException;
import com.dabaozhan.common.utils.ValidationBeanUtils;
import com.dabaozhan.modules.wx_app.base.ResponseDto;
import com.dabaozhan.modules.wx_app.entity.OperateFormEntity;
import com.dabaozhan.modules.wx_app.entity.OperateQueryEntity;
import com.dabaozhan.modules.wx_app.enums.ResponseCodeEnum;
import com.dabaozhan.modules.wx_app.facade.OperateFormFacade;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value = "运营报表")
@RestController
@RequestMapping("/wx_app")
public class OperateFormController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(OperateFormController.class);
	
	@Autowired
	private OperateFormFacade operateFormFacade;

	@ApiOperation(value = "运营报表")
    @RequestMapping(value = "/getOperate")
	public String getOperate(OperateQueryEntity entity){
		ResponseDto<OperateFormEntity> responseDto = new ResponseDto<OperateFormEntity>();
		try{
			//验证参数是否为空
			ValidationBeanUtils.validateBeanRequestDto(entity);
			OperateFormEntity result = operateFormFacade.getOperate(entity);
			responseDto.setResult(result);
			responseDto.setResponseCodeEnum(ResponseCodeEnum.ResponseCode_100);
		}catch(RRException re){
			responseDto.setCode(re.getCode());
			responseDto.setMessage(re.getMessage());
		}catch (Exception e) {
			responseDto.setResponseCodeEnum(ResponseCodeEnum.ResponseCode_500);
			//记录异常日志
			LOGGER.error("查询运营报表发生异常,异常详情如下:",e);
		}finally{
			//记录请求入参和返回日志
			LOGGER.info("查询运营报表请求参数:{}-返回结果:{}",JSON.toJSONString(entity),JSON.toJSONString(responseDto));
		}
		return JSON.toJSONString(responseDto);
	}


}
